//
//  doubleTableView.m
//  HomeFurnishing
//
//  Created by dllo on 16/3/28.
//  Copyright © 2016年 YMing. All rights reserved.
//

#import "doubleTableView.h"
#import "DoubleTableViewCell.h"
#import "CaseDBaseModel.h"
#import "DetailCaseVC.h"
@interface doubleTableView ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, retain)UITableView *tv;
@property(nonatomic, retain)NSMutableArray *dataArr;
@end

@implementation doubleTableView

-(void)dealloc
{
    [_tv release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


- (instancetype)initWithFrame:(CGRect)frame 
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
        _tv.dataSource = self;
        _tv.delegate = self;
        _tv.backgroundColor = [UIColor yellowColor];
        _tv.rowHeight = 270;
        self.tv.tableFooterView = [[UIView alloc] init];
        [self addSubview:self.tv];
        [_tv registerClass:[DoubleTableViewCell class] forCellReuseIdentifier:@"tvCell"];
        [_tv  release];
        [_tv.tableFooterView release];
        [self dataHandle];
        
    }
    return self;
}

-(void)dataHandle
{
    [NetworkHandle GetDataWithURL:@"http://api.guju.com.cn/v2/project/list?proceed=1&stage=0&city=0&user=(null)&start=0&count=10" dic:nil success:^(id responseObject) {
        self.dataArr = [CaseDBaseModel transformWithArray:responseObject[@"projects"]];
        //NSLog(@"%@",_dataArr);
        
        [_tv reloadData];
    } filed:^(NSError *error) {
        
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DoubleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tvCell" forIndexPath:indexPath];
    
    CaseDBaseModel *m = _dataArr[indexPath.row];
    cell.title.text = m.title;
    cell.detailAddress.text = m.detailAddress;
    [cell.userImgView sd_setImageWithURL:[NSURL URLWithString:m.small]];
    [cell.btn setTitle:m.stageShow forState:(UIControlStateNormal)];
    NSString *str = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w750_h398_m0.jpg",m.coverPhoto];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"24099F061BD92F37796E9B75C3ED9531.jpg"]];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.delegate didSelectRowAtIndexPath:indexPath array:_dataArr];
    
}
@end
